package com.qufenqi.pay.abs.common.exception;

import org.apache.commons.lang.StringUtils;

public enum ErrorCodeEnum {

    SYS_ERROR_0001("SYS_ERROR_0001", "系统错误：网络开小差"),

    BIZ_ERROR_0001("BIZ_ERROR_0001", "不能为空"),
    BIZ_ERROR_002("BIZ_ERROR_0002", "业务异常!RcCode冲突!请联系管理员"),
    BIZ_FileNotNull("BIZ_ERROR_0003", "文件不能为空"),
    BIZ_SAVE_ERROR("BIZ_ERROR_0003", "文件不能为空"),

    SYS_SUCCESS_SAVE("1", "保存成功"),
    SYS_INVALID("1", "操作成功,作废执行中"),

    LEND_SUMMARY_ERROR("9998", "借款汇总执行异常"),;

    private String code;
    private String msg;

    private ErrorCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getNameByCode(String code) {
        if (StringUtils.isBlank(code)) return null;
        for (ErrorCodeEnum accountInfoEnum : ErrorCodeEnum.values()) {
            if (code.equals(accountInfoEnum.getCode())) {
                return accountInfoEnum.getMsg();
            }
        }
        return null;
    }

    public static String getCodeByName(String name) {
        if (StringUtils.isBlank(name)) return null;
        for (ErrorCodeEnum accountInfoEnum : ErrorCodeEnum.values()) {
            if (name.equals(accountInfoEnum.getMsg())) {
                return accountInfoEnum.getCode();
            }
        }
        return null;
    }

}
